package ${project.packageName}.${project.dataCenterType}.ctrl;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import ${project.packageName}.${project.dataCenterType}.client.jedis.JedisActionClient;
import ${project.packageName}.${project.dataCenterType}.constant.BaseConstant;
import ${project.packageName}.${project.dataCenterType}.entity.JsonResult;


@RestController
@RequestMapping("/${project.version}")
public class ${ctrlName}Controller {

    private final static Logger LOG = LoggerFactory.getLogger(${ctrlName}Controller.class);

    @Autowired
    private JedisActionClient jedisActionClient;

   
     /**
     * Description: ${restApi.description}
     <#list paraMaps as para>
     * @param ${para.name}
     </#list>
     */
    @SuppressWarnings("unchecked")
     @RequestMapping(value = "${restApi.requestUrl}", method = RequestMethod.${restApi.requestType})
     public Object ${methodName}( HttpServletRequest request<#list paraMaps as para>, @RequestParam(required=${para.isMust}) ${para.type} ${para.name}</#list> ){
        ${rowkeyStatements}
        HashMap<String, String> map = (HashMap<String, String>)jedisActionClient.getObject(key);

        if (map == null) {
            // 用户不存在
            LOG.error("map does not exist");
            return new JsonResult(BaseConstant.CODE_NON_EXISTENT, BaseConstant.MSG_NON_EXISTENT);
        }
        if (!map.get("psd").equals(password)) {
            // 密码错误
            LOG.error("password  error");
            return new JsonResult(BaseConstant.CODE_WRONG_PASSWORD,
                BaseConstant.MSG_WRONG_PASSWORD);
        }

        LOG.info(JSONObject.toJSONString(map));

        JSONObject jsonObject = new JSONObject();

        <#list returnValMaps as returnVal>
          jsonObject.put("${returnVal.name}",map.get("${returnVal.name}"));
        </#list>
        return JSON.toJSONString(jsonObject);
    }
}
 